/**
 * Created by IntelliJ IDEA.
 * User: ryan
 * Date: Sep 14, 2010
 * Time: 5:39:43 PM
 * Test of the LineShark library
 */
$(function() {
	module('lineShark');

	test("Basic Types", 4, function() {
		var actual = lineShark.eatLine("[]Get a Rake");
        var expected = {
            text: "Get a Rake",
            type: "actionable"
        };
		same(actual, expected, "Action Item");

   		actual = lineShark.eatLine("I have many apples.");
        expected = {
            text: "I have many apples.",
            type: "reference"
        };
		same(actual, expected, "Reference");

   		actual = lineShark.eatLine("#Calgary_Flames");
        expected = {
            type: "topicChange",
            topic: "Calgary_Flames"
        };
		same(actual, expected, "Topic");

   		actual = lineShark.eatLine("? How much is that dog in the window?");
        expected = {
            type: "actionable",
            subtype: "question",
            text: "How much is that dog in the window?"
        };
		same(actual, expected, "Topic");
	});

    test("combos", 6, function() {
        var actual = lineShark.eatLine("[]Get a Rake @Home_Depot #Gardening");
        var expected = {
            type: "actionable",
            text: "Get a Rake",
            context: "Home_Depot",
            topic: "Gardening"

        };
		same(actual, expected, "Action Item, Context, Topic");

        var actual = lineShark.eatLine("[]Get a Rake @Home_Depot !Ryan_Ramage #Gardening");
        var expected = {
            type: "actionable",
            text: "Get a Rake",
            context: "Home_Depot",
            delegate: "Ryan_Ramage",
            topic: "Gardening"

        };
		same(actual, expected, "Action Item, Context, Delegate, Topic");

        var actual = lineShark.eatLine("[]Get a Rake@Home_Depot!Ryan_Ramage#Gardening");
        var expected = {
            type: "actionable",
            text: "Get a Rake",
            context: "Home_Depot",
            delegate: "Ryan_Ramage",
            topic: "Gardening"

        };
		same(actual, expected, "SQUISH - Action Item, Context, Delegate, Topic");

        var actual = lineShark.eatLine("[]Get a Rake #Gardening #Home_Depot");
        var expected = {
            type: "actionable",
            text: "Get a Rake",
            topic: "Home_Depot"

        };
		same(actual, expected, "Duplicate topics, last one wins");

        var actual = lineShark.eatLine("?How much whould a rake be? #Gardening ");
        var expected = {
            type: "actionable",
            subtype: "question",
            text: "How much whould a rake be?",
            topic: "Gardening"

        };
		same(actual, expected, "Question");

        var actual = lineShark.eatLine("[]Get a Rake ^01-01-2010");
        var expected = {
            type: "actionable",
            text: "Get a Rake",
            date: 1262329200000

        };
		same(actual, expected, "Date");

    });

    test("context", 7, function() {

        var context = {
          conversation : "Meeting_With_Bob_(2010-01-10)",
          timestamp: 1262329200000,
          me: "Ryan_Ramage"
        };
        var actual = lineShark.eatLine("[]Get a Rake !me", context);
        var expected = {
            type: "actionable",
            text: "Get a Rake",
            delegate: "Ryan_Ramage",
            conversation: "Meeting_With_Bob_(2010-01-10)",
            timestamp: 1262329200000
        };
        same(actual, expected, "!me with context");


        var context = {
          conversation : "Meeting_With_Bob_(2010-01-10)",
          timestamp: 1262329200000,
          me: "Ryan_Ramage",
          topicStack: ["Mission_To_Mars", "Boosters"]
        };
        var actual = lineShark.eatLine("? How much fuel will we need?", context);
        var expected = {
            type: "actionable",
            subtype: "question",
            text: "How much fuel will we need?",
            conversation: "Meeting_With_Bob_(2010-01-10)",
            timestamp: 1262329200000,
            topicStack: ["Mission_To_Mars","Boosters"]
        };
        same(actual, expected, "topic stack");
        equals(context.topicStack.length, 2, "Topic Stack Preserved");  


        var context = {
          conversation : "Meeting_With_Bob_(2010-01-10)",
          timestamp: 1262329200000,
          me: "Ryan_Ramage",
          topicStack: ["Mission_To_Mars", "Boosters"]
        };
        var actual = lineShark.eatLine("[] Call Manufacturer for refund #Defects", context);
        var expected = {
            type: "actionable",
            text: "Call Manufacturer for refund",
            topic: "Defects",
            conversation: "Meeting_With_Bob_(2010-01-10)",
            timestamp: 1262329200000,
            topicStack: ["Mission_To_Mars", "Boosters"]
        };
        same(actual, expected, "topic stack, topic in text ");
        equals(context.topicStack.length, 2, "Topic Stack Preserved");

        var context = {
          conversation : "Meeting_With_Bob_(2010-01-10)",
          timestamp: 1262329200000,
          me: "Ryan_Ramage",
          topicStack: ["Mission_To_Mars", "Boosters"]
        };
        var actual = lineShark.eatLine("#Defects", context);
        var expected = {
            type: "topicChange",
            topic: "Defects",
            conversation: "Meeting_With_Bob_(2010-01-10)",
            timestamp: 1262329200000,
            topicStack: ["Mission_To_Mars", "Boosters"]
        };
        same(actual, expected, "topic stack change topic ");



        var context = {
          conversation : "Meeting_With_Bob_(2010-01-10)",
          timestamp: 1262329200000,
          me: "Ryan_Ramage",
          topicStack: ["Mission_To_Mars", "Boosters"]
        };
        var actual = lineShark.eatLine("?who will be the new Manufacturer?", context);
        var expected = {
            type: "actionable",
            subtype: "question",
            text: "who will be the new Manufacturer?",
            conversation: "Meeting_With_Bob_(2010-01-10)",
            timestamp: 1262329200000,
            topicStack: ["Mission_To_Mars", "Boosters"]
        };
        same(actual, expected, "topic stack change topic ");

    });
});
